﻿using Cms.Core.Infrastructure.Common;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;
namespace Cms.Core.Infrastructure.Ui
{
    public   class OperationResult : OperationResult<object>
    {
        public OperationResult() : base(OperationResultType.Success)
        {


        }
        public OperationResult(OperationResultType type = OperationResultType.Success) : base("", null, type)
        {


        }
        public OperationResult(string message, OperationResultType type) : base(message, null, type)
        {


        }
        public OperationResult(string message, object data, OperationResultType type) : base(message, data, type)
        {
        }

    }

    public class OperationResult<TData>
    {
        public OperationResult() : this(OperationResultType.Success)
        {


        }
        public OperationResult(OperationResultType type = OperationResultType.Success) : this("", default(TData), type)
        {


        }
        public OperationResult(string message, OperationResultType type) : this(message, default(TData), type)
        {


        }
        public OperationResult(string message, TData data, OperationResultType type)
        {
            Message = message;
            Type = type;
            Data = data;

        }


        [JsonProperty("message")]
        public  string Message { get; set; }

        [JsonProperty("data")]
        public  TData Data { get; set; }

        [JsonProperty("type")]
        public  OperationResultType Type { get; set; }

        [JsonProperty("successed")]
        public bool Successed => Type == OperationResultType.Success;

        public bool Error()
        {
            return Type != OperationResultType.Success;
        }

        public bool Exp()
        {
            return Type == OperationResultType.Exp;
        }
    }
}
